package com.woniu.service.impl;

import com.woniu.entity.OrderItems;
import com.woniu.mapper.OrderItemsMapper;
import com.woniu.service.OrderItemsService;
import com.woniu.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OrderItemsServiceImpl implements OrderItemsService {

    SqlSession sqlSession = MyBatisUtil.getSqlSession();
    OrderItemsMapper mapper = sqlSession.getMapper(OrderItemsMapper.class);
    @Override
    public void insertOrderItems(OrderItems orderItems) {
      mapper.insertOrderItem(orderItems);
      sqlSession.commit();
      sqlSession.close();
    }

    @Override
    public List<OrderItems> getOrderItems(Integer id) {
        List<OrderItems> orders = mapper.getOrderItemsByOrderId(id);
        return orders;
    }

    @Override
    public void deleteOrderItems(Integer id) {
        mapper.deleteOrderItemsByOrderId(id);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<OrderItems> getOrderItemsByMid(Integer mid) {
         List<OrderItems> orderItemsByMid = mapper.getOrderItemsByMid(mid);
         return orderItemsByMid;
    }

    @Override
    public void updateOrderItemsStatus(Integer merchant_id, int status) {
        mapper.updateOrderItemsStatus(merchant_id, status);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void updateOrderItemsByOrderId(Integer order_id, int status) {
        mapper.updateOrderItemsByOrderId(order_id, status);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<OrderItems> getOrderItemsByStatus(Integer merchant_id, Integer status) {
        List<OrderItems> orderItemsByStatus = mapper.getOrderItemsByStatus(merchant_id, status);
        return orderItemsByStatus ;
    }

    @Override
    public void deleteByMid(Integer merchant_id, Integer status) {
        mapper.deleteByMid(merchant_id, status);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<OrderItems> getOrderItemsByPid(Integer merchant_id, Integer pid) {
       List<OrderItems> orderItemsByPid = mapper.getOrderItemsByPid(merchant_id, pid);
        return orderItemsByPid;
    }

    @Override
    public void updateOrderItemsByOrderItemId(Integer order_item_id, int status) {
        mapper.updateOrderItemsByOrderItemId(order_item_id, status);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<OrderItems> getOrderItemsByStatus(Integer status) {
        List<OrderItems> orderItemsByStatus = mapper.selectOrderItemsByStatus(status);
        return orderItemsByStatus;
    }

    @Override
    public List<OrderItems> getOrderItemsIf(Integer product_id, Integer merchant_id) {
         List<OrderItems> orderItemsIf = mapper.getOrderItemsIf(product_id, merchant_id);
        return orderItemsIf;
    }

    @Override
    public List<OrderItems> selectOrderItemsByPid(Integer pid) {
        List<OrderItems> orderItems = mapper.selectOrderItemsByPid(pid);
        return orderItems;
    }


}
